
package com.powerunion.datacollection.report.excelreport.base.element;

import java.util.Map;

import com.powerunion.datacollection.report.excelreport.base.Parameter;


/**
 * 一个参数类变量的实现一个参数变量类的具体实例代表了一个具体参数。
 * @author juny
 */
public class ParameterVariable extends Variable{
    public ParameterVariable(String paramTemplet){
        if(null != paramTemplet && !"".equals(paramTemplet)){
            setName(paramTemplet);
            paramName = paramTemplet;
        }
    }
    
    /*
     * (non-Javadoc)
     * @see net.excel.report.base.element.Variable#setParam(net.excel.report.base.Parameter)
     */
    public void setParam(Parameter param){
        this.setParam(param.params);
    }
    
    /**
     * 设置参数变量的参数
     * @param params
     */
    public void setParam(Map params){
        if(null != paramName){
            //取得参数值
            paramValue = (String)params.get(paramName);
            //设置参数值为字符串类型
            this.setValueType(STRING);
        }
    }
    
    /* (non-Javadoc)
     * @see excel.report.util.Variable#getValue()
     */
    public Object getValue() throws Exception {
        if(null != paramValue){
            return getValueByType(paramValue);
        }else{
            return null;
        }  
    }
    
    /*
     * (non-Javadoc)
     * @see net.excel.report.base.element.Variable#getString()
     */
    public String getString() throws Exception {
        return paramValue;
    }
    
    /*
     * (non-Javadoc)
     * @see net.excel.report.base.element.Variable#getType()
     */
    public byte getType(){
        return VARIABLE_TYPE_PARAMETER;
    }
    
    public String toString(){
        return "parameter: name=" + paramValue;
    }
    
    private String paramName = null;
    private String paramValue = null;
}
